//
//  FindViewController.m
//  AriseSamePro
//
//  Created by 包日守 on 15/10/22.
//  Copyright © 2015年 Arise. All rights reserved.
//

#import "FindViewController.h"
#import "FindUpdataViewController.h"
#import "FindRecomentViewController.h"
#import "ChannelTableViewController.h"
#import "FXBlurView.h"
#import "SearchView.h"
#import "ARSearchViewController.h"
#import "ARChannelTableViewFactory.h"

@interface FindViewController ()<FindRecomentViewControllerDelegate,FindUpdataViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedControl;

@property (nonatomic,strong) FindUpdataViewController *updataViewController;
@property (nonatomic,strong) FindRecomentViewController *recomentViewController;
@end

@implementation FindViewController

- (FindUpdataViewController *)updataViewController
{
    if (_updataViewController == nil) {
        _updataViewController = [[FindUpdataViewController alloc] init];
        [self.view addSubview:_updataViewController.view];
        
        _updataViewController.delegate = self;
    }
    return _updataViewController;

}

- (FindRecomentViewController *)recomentViewController
{
    if (_recomentViewController == nil) {
        _recomentViewController = [[FindRecomentViewController alloc] init];
        _recomentViewController.delegate = self;
        
        [self.view addSubview:_recomentViewController.view];
    }
    
    return  _recomentViewController;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //默认调用第一个界面
    

    
    self.recomentViewController.view.backgroundColor = [UIColor clearColor];

    
    
    

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showMoreViewCotroller:) name:@"showMore" object:nil];

}

- (void)showMoreViewCotroller:(NSNotification *)sender
{
    /*
    NSString * index = sender.userInfo[@"index"];
    NSString *title = sender.userInfo[@"title"];
    
    ChannelTableViewController *channelTableViewController = [[ChannelTableViewController alloc] init];
    channelTableViewController.title = title;
    channelTableViewController.index = index;
    channelTableViewController.hidesBottomBarWhenPushed = YES;
    
    [self.navigationController pushViewController:channelTableViewController animated:YES];
     */
    
    [self performSegueWithIdentifier:@"ShowChannel" sender:sender.userInfo];
    
}


- (IBAction)segmentControlClick:(id)sender {
    
    if (self.segmentedControl.selectedSegmentIndex == 0) {
        [self.view bringSubviewToFront:self.recomentViewController.view];
    }
    else
    {
        [self.view bringSubviewToFront:self.updataViewController.view];
    }
    
    
}


- (IBAction)searchButtonClick:(id)sender {
    
 
    
    ARSearchViewController *svc = [[ARSearchViewController alloc] init];
    svc.hidesBottomBarWhenPushed = YES;
    
    [self.navigationController pushViewController:svc animated:YES];
    
   /*
    
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"SearchView" owner:nil options:nil];
        SearchView *searchV = [array lastObject];
    
    //searchV.blurRadius = 15;

    [self.tabBarController.view addSubview:searchV];
    */
 
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
    if ([segue.identifier isEqualToString:@"ShowChannel"]) {
        
        
        NSString * index = sender[@"index"];
        NSString *title = sender[@"title"];
        NSString *cate = sender[@"cate"];
        ChannelTableViewController *channelTableViewController = [segue destinationViewController];;
        channelTableViewController.title = title;
        channelTableViewController.index = index;
        channelTableViewController.hidesBottomBarWhenPushed = YES;
        channelTableViewController.cate = cate;
        
        
        
    }
    
    
    
}

#pragma mark - FindUpdataViewControllerDelegate

- (void) findUpdataViewController:(FindUpdataViewController *)upViewController WithChannel:(ARChannelModel *)channel
{
    
    ChannelTableViewController *channelVC = [ARChannelTableViewFactory channelTableViewWithCate:channel.cate WithTitle:channel.name WithIndex:channel.index];
    
    if (channelVC) {
        [self.navigationController pushViewController:channelVC animated:YES];
    }
    /*
    
    if (![channel.cate isEqualToString:@"3"]&&![channel.cate isEqualToString:@"8"]) {
        return;
    }
    
    ChannelTableViewController *channelTableViewController = [[ChannelTableViewController alloc] init];
    
    
    
    channelTableViewController.title = channel.name;
    channelTableViewController.index = channel.index;
    channelTableViewController.hidesBottomBarWhenPushed = YES;
    channelTableViewController.cate = channel.cate;
    
    [self.navigationController pushViewController:channelTableViewController animated:YES];
     */

}

#pragma mark - FindRecomentViewControllerDelegate

- (void) findRecomentViewController:(FindRecomentViewController *)findRecomentVC WithChannel:(ARChannelModel *)channelModel
{
    
    ChannelTableViewController * channelVC;
    
    channelVC = [ARChannelTableViewFactory channelTableViewWithCate:channelModel.cate WithTitle:channelModel.name WithIndex:channelModel.index];
    
    if (channelVC) {
        [self.navigationController pushViewController:channelVC animated:YES];
    }
    
    /*
    
    if (![channelModel.cate isEqualToString:@"3"]) {
        return;
    }
    
    ChannelTableViewController *channelTableViewController = [[ChannelTableViewController alloc] init];
    
    
    
    channelTableViewController.title = channelModel.name;
    channelTableViewController.index = channelModel.index;
    channelTableViewController.hidesBottomBarWhenPushed = YES;
    channelTableViewController.cate = channelModel.cate;
    
    [self.navigationController pushViewController:channelTableViewController animated:YES];
*/
}


@end
